package com.laiketui.common.mapper;

import com.laiketui.domain.plugin.auction.AuctionPromiseModel;
import com.laiketui.core.db.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * 保证金记录表
 *
 * @author Trick
 */
public interface AuctionPromiseModelMapper extends BaseMapper<AuctionPromiseModel> {

    /**
     * 专场是否支付了保证金
     */
    @Select("select count(1) from lkt_auction_promise a where a.is_pay=1 and a.is_back is null and a.store_id=#{storeId} and a.id=#{specialId} and a.user_id=#{userId}")
    int isPayPromiseByAcId(int storeId, String specialId, String userId);

    /**
     * 竞拍支付保证金
     *
     * @param storeId -
     * @param orderNo -
     * @param isPay   -
     * @return int
     * @author Trick
     * @date 2022-07-18 14:20:43
     */
    @Update("update lkt_auction_promise set is_pay = #{isPay} where store_id = #{storeId} and trade_no = #{orderNo} ")
    int updateStatus(int storeId, String orderNo, int isPay);

    /**
     * 竞拍押金置为，暂不退款，只有付款后，才置为可退款，并进行退款
     *
     * @param storeId -
     * @param aid     -
     * @param userId  -
     * @param status  -0 未达到退款标准
     * @return int
     * @author Trick
     * @date 2021/4/24 10:45
     */
    @Update("update lkt_auction_promise set allow_back = #{status} where store_id = #{storeId} and a_id = #{aid} and user_id = #{userId}")
    int updateAllowBack(int storeId, int aid, String userId, int status);


    /**
     * 获取保证金记录列表
     *
     * @param map -
     * @return int
     * @author Trick
     * @date 2021/5/17 12:21
     */
    List<Map<String, Object>> selectAuctionPromiseList(Map<String, Object> map);

    int countAuctionPromiseList(Map<String, Object> map);

}